package com.trade.tradebusiness.trade.order;


import com.trade.core.exception.TradeBaseException;
import com.trade.core.message.TradeObjectRestResponse;
import com.trade.core.trade.TradeProcessorStepAbstract;
import com.trade.tradebusiness.entity.dto.TradeCreateOrderAfterDTO;
import com.trade.tradebusiness.entity.vo.TradeCreateOrderAfterVO;
import com.trade.tradebusiness.enums.OrderTradeProcessorStepEnums;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author sven.wang
 * @version 2022/1/6 15:26
 * @Description: 下单后处理
 */
@Service
@Slf4j
public class CreateOrderAfterTradeStep extends TradeProcessorStepAbstract<TradeCreateOrderAfterDTO,TradeCreateOrderAfterVO> {

    @Override
    public String step() {
        return OrderTradeProcessorStepEnums.ORDER_AFTER.name();
    }

    @Override
    public void checkParam(TradeCreateOrderAfterDTO param) {

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public TradeObjectRestResponse<TradeCreateOrderAfterVO> doProcess(TradeCreateOrderAfterDTO param) {


        TradeCreateOrderAfterVO vo = new TradeCreateOrderAfterVO();
        vo.setOrderId(param.getOrderId());
        return TradeObjectRestResponse.success(vo);
    }

    @Override
    public void checkOutParam(TradeCreateOrderAfterVO outParam) {
        if(StringUtils.isBlank(outParam.getOrderId())){
            throw new TradeBaseException("步骤返回数据异常: 订单id不存在");
        }
    }

}
